<template>
	<view>
		<view v-for="(item,index) in likeList" :key="index">
			<uni-section type="line">
				<uni-card title="基础卡片" sub-title="副标题" extra="额外信息" padding="10px 0" :thumbnail="avatar">
					<template v-slot:title>
						<uni-list>
							<uni-list-item :title="item.data[0].title" />
						</uni-list>
					</template>
					<image style="width: 100%;" :src="item.data[0].Image[0]" mode="aspectFill"></image>
					<text
						class="uni-body uni-mt-5">{{item.data[0].content}}</text>
					<view slot="actions" class="card-actions">
						<view class="card-actions-item" @click="">
							<uni-icons type="redo" size="18" color="#999"></uni-icons>
							<text class="card-actions-item-text">分享</text>
						</view>
						<view class="card-actions-item" @click="actionsClick(item.data[0]._id,index)">
							<uni-icons type="heart-filled" size="18" color="#999"></uni-icons>
							<text class="card-actions-item-text">点赞</text>
						</view>
						<view class="card-actions-item" @click="">
							<uni-icons type="chatbubble" size="18" color="#999"></uni-icons>
							<text class="card-actions-item-text">评论</text>
						</view>
					</view>
				</uni-card>
			</uni-section>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	export default {
		data() {
			return {
				likeList: [],
				cover: 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/shuijiao.jpg',
				avatar: 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/unicloudlogo.png',
				extraIcon: {
					color: '#4cd964',
					size: '22',
					type: 'gear-filled'
				},
				list:[]
			}
		},
		computed: mapState(['hasLogin', 'uerInfo']),
		onLoad() {
			this.getLike()
		},
		methods: {
			getLike() {
				uniCloud.callFunction({
					name: 'user',
					data: {
						aname: this.uerInfo.userName
					}
				}).then(res => {
					//请求喜欢的返回值
					uniCloud.callFunction({
						name: 'findLike',
						data: {
							likeArr: res.result.data[0].like
						}
					}).then(res1 => {
						this.likeList = res1.result
					})
				})
			},
			onClick(e) {
				console.log(e)
			},
			actionsClick(text,index) {
				this.likeList.splice(index,1)
				for(let i=0;i<this.likeList.length;i++){
					this.list.push(this.likeList[i].data[0]._id)
				}
				console.log(this.list)
				uniCloud.callFunction({
					name: 'setUser',
					data: {
						aname: this.uerInfo.userName,
						like: this.list
					}
				}).then(res => {
					console.log(res)
				})
			}
		}

	}
</script>

<style lang="scss" scoped>
	.container {
		overflow: hidden;
	}

	.custom-cover {
		flex: 1;
		flex-direction: row;
		position: relative;
	}

	.cover-content {
		position: absolute;
		bottom: 0;
		left: 0;
		right: 0;
		height: 40px;
		background-color: rgba($color: #000000, $alpha: 0.4);
		display: flex;
		flex-direction: row;
		align-items: center;
		padding-left: 15px;
		font-size: 14px;
		color: #fff;
	}

	.card-actions {
		display: flex;
		flex-direction: row;
		justify-content: space-around;
		align-items: center;
		height: 45px;
		border-top: 1px #eee solid;
	}

	.card-actions-item {
		display: flex;
		flex-direction: row;
		align-items: center;
	}

	.card-actions-item-text {
		font-size: 12px;
		color: #666;
		margin-left: 5px;
	}

	.cover-image {
		flex: 1;
		height: 150px;
	}

	.no-border {
		border-width: 0;
	}
</style>